import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    cacheArr: ["index"],
    content: "+关注",
    // session存储用户信息
    userInfo:
      sessionStorage.getItem("userInfo") &&
      JSON.parse(sessionStorage.getItem("userInfo")),
  },
  getters: {
    // 类似get请求
    // 获取用户信息
    getUser: (state) => {
      return state.userInfo;
    },
  },
  mutations: {
    userInfo: (state, userInfo) => {
      state.userInfo = userInfo;
      // sessionStorage不能存储对象，所以要将其储存成字符串的形式
      sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
    },
    UpdateContent(state, content) {
      state.content = content;
    },
  },
  actions: {},
  modules: {},
});
